import { app, BrowserWindow } from 'electron'
import type { BrowserWindowConstructorOptions } from 'electron'
import { CustomScheme } from './CustomScheme'

// 禁用渲染进程开发者调试工具井盖
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true'

let mainWindow: BrowserWindow

app.whenReady().then(async () => {
  const config: BrowserWindowConstructorOptions = {
    width: 1080,
    height: 800,
    webPreferences: {
      nodeIntegration: true, // 是否在js环境中集成node
      webSecurity: false, // 是否禁用同源策略
      allowRunningInsecureContent: true, // 允许一个 https 页面运行来自http url的JavaScript, CSS 或 plugins
      contextIsolation: false,
      webviewTag: true,
      spellcheck: false, //  是否启用内置拼写检查器
      disableHtmlFullscreenWindowResize: true // 是否禁用在html全屏时调整窗口大小
    }
  }

  mainWindow = new BrowserWindow(config)
  mainWindow.webContents.openDevTools({ mode: 'right' })
  if (process.argv[2]) {
    await mainWindow.loadURL(process.argv[2])
  } else {
    CustomScheme.registerScheme()
    await mainWindow.loadURL(`app://index.html`)
  }

  setTimeout(() => {
    console.log('发布事件debug123')
    mainWindow.webContents.send('debug', 'mainData')
  }, 2000)
})
